"""
@Author : Jenkin
@Date : 2021/1/12 21:58 
@Description boundary deal
"""

import cv2
import numpy as np


def origin_to_boundary(path=r"E:\zjk\Python project\texture_filler\dataset\DUTS-TE-Mask\ILSVRC2012_test_00000324.png"):
    """
    生成边缘，仅应用于两个连通区域
    :param path:
    :return:
    """
    origin = cv2.imread(path)
    ret, origin = cv2.threshold(origin, 127, 255, cv2.THRESH_BINARY)
    res = cv2.blur(origin, (3, 3))
    boundary1 = origin - res
    boundary1[origin == 0] = 0  # 非白色区域归零
    boundary1[boundary1 > 0] = 255  # 边缘区域变白
    boundary1[:, :, 2][boundary1[:, :, 2] == 255] = 0
    boundary1[:, :, 1][boundary1[:, :, 1] == 255] = 0

    boundary2 = origin - res
    boundary2[origin == 255] = 0
    boundary2[boundary2 > 0] = 255
    boundary2[:, :, 0][boundary2[:, :, 0] == 255] = 0
    boundary2[:, :, 1][boundary2[:, :, 1] == 255] = 0

    cv2.imwrite("01boundary1.png", boundary1)
    cv2.imwrite("01boundary2.png", boundary2)
    cv2.imwrite("01boundary1+2.png", boundary1 + boundary2)


def image_hybrid(path1=r"5096.bmp",
                 path2=r"5096.jpg"):
    """
    图片混合
    :param path1:
    :param path2:
    :return:
    """
    img1 = cv2.imread(path1)
    img2 = cv2.imread(path2)
    dst = cv2.addWeighted(img1, 0.5, img2, 0.5, 0)
    cv2.imwrite("hybrid.png", dst)


if __name__ == '__main__':
    # origin_to_boundary()
    image_hybrid()